load("//rs/tests:common.bzl", "GRAFANA_RUNTIME_DEPS", "IC_GATEWAY_RUNTIME_DEPS", "NNS_CANISTER_ENV", "NNS_CANISTER_RUNTIME_DEPS", "SNS_CANISTER_ENV", "SNS_CANISTER_RUNTIME_DEPS")
load("//rs/tests:system_tests.bzl", "system_test", "system_test_nns")

package(default_visibility = ["//rs:system-tests-pkg"])

IC_GATEWAY_UVM_IMAGE = [
    "//rs/tests:ic_gateway_uvm_config_image",
]

# the "_test" postfixes in names are dropped on purpose since this target is meant for interactive use.

system_test(
    name = "single_large_node",
    tags = [
        "dynamic_testnet",
        "manual",
    ],
    visibility = ["//visibility:public"],  # public because part of top-level manual test suite
    runtime_deps = GRAFANA_RUNTIME_DEPS,
    deps = [
        # Keep sorted.
        "//rs/registry/subnet_type",
        "//rs/tests/driver:ic-system-test-driver",
        "@crate_index//:anyhow",
    ],
)

system_test(
    name = "single_app_large_node",
    tags = [
        "dynamic_testnet",
        "manual",
    ],
    runtime_deps = GRAFANA_RUNTIME_DEPS,
    deps = [
        # Keep sorted.
        "//rs/registry/subnet_type",
        "//rs/tests/driver:ic-system-test-driver",
        "@crate_index//:anyhow",
    ],
)

system_test_nns(
    name = "single_app_large_node_with_nns",
    tags = [
        "dynamic_testnet",
        "manual",
    ],
    runtime_deps = GRAFANA_RUNTIME_DEPS,
    deps = [
        # Keep sorted.
        "//rs/registry/subnet_type",
        "//rs/tests/consensus/utils",
        "//rs/tests/driver:ic-system-test-driver",
        "@crate_index//:anyhow",
    ],
)

system_test(
    name = "single_app_small_node",
    tags = [
        "dynamic_testnet",
        "manual",
    ],
    runtime_deps = GRAFANA_RUNTIME_DEPS,
    deps = [
        # Keep sorted.
        "//rs/registry/subnet_type",
        "//rs/tests/driver:ic-system-test-driver",
        "@crate_index//:anyhow",
    ],
)

system_test_nns(
    name = "small",
    tags = [
        "dynamic_testnet",
        "manual",
    ],
    runtime_deps = GRAFANA_RUNTIME_DEPS + IC_GATEWAY_UVM_IMAGE,
    deps = [
        # Keep sorted.
        "//rs/registry/subnet_type",
        "//rs/tests/consensus/utils",
        "//rs/tests/driver:ic-system-test-driver",
        "@crate_index//:anyhow",
    ],
)

system_test_nns(
    name = "small_bitcoin",
    tags = [
        "dynamic_testnet",
        "manual",
    ],
    runtime_deps = GRAFANA_RUNTIME_DEPS + IC_GATEWAY_UVM_IMAGE,
    deps = [
        # Keep sorted.
        "//rs/registry/subnet_type",
        "//rs/tests/consensus/utils",
        "//rs/tests/driver:ic-system-test-driver",
        "@crate_index//:anyhow",
        "@crate_index//:slog",
    ],
)

system_test_nns(
    name = "small_high_perf",
    tags = [
        "dynamic_testnet",
        "manual",
    ],
    runtime_deps = GRAFANA_RUNTIME_DEPS + IC_GATEWAY_UVM_IMAGE,
    deps = [
        # Keep sorted.
        "//rs/registry/subnet_type",
        "//rs/tests/consensus/utils",
        "//rs/tests/driver:ic-system-test-driver",
        "@crate_index//:anyhow",
        "@crate_index//:slog",
    ],
)

system_test(
    name = "from_config",
    env = NNS_CANISTER_ENV,
    tags = [
        "dynamic_testnet",
        "manual",
    ],
    runtime_deps = GRAFANA_RUNTIME_DEPS + NNS_CANISTER_RUNTIME_DEPS,
    deps = [
        "//rs/tests/dre/utils:os_qualification_utils",
        "//rs/tests/driver:ic-system-test-driver",
        "@crate_index//:anyhow",
        "@crate_index//:serde_json",
    ],
)

system_test_nns(
    name = "small_nns",
    env = {
        "IC_ICRC1_LEDGER_WASM_PATH": "$(rootpath //rs/ledger_suite/icrc1/ledger:ledger_canister)",
        "II_WASM_PATH": "$(rootpath @ii_dev_canister//file)",
        "NNS_DAPP_WASM_PATH": "$(rootpath @nns_dapp_canister//file)",
        "SUBNET_RENTAL_WASM_PATH": "$(rootpath @subnet_rental_canister//file)",
    },
    tags = [
        "dynamic_testnet",
        "manual",
    ],
    runtime_deps = GRAFANA_RUNTIME_DEPS + IC_GATEWAY_UVM_IMAGE + [
        "//rs/ledger_suite/icrc1/ledger:ledger_canister",
        "@ii_dev_canister//file",
        "@nns_dapp_canister//file",
        "@subnet_rental_canister//file",
    ],
    deps = [
        # Keep sorted.
        "//rs/registry/subnet_type",
        "//rs/tests/consensus/utils",
        "//rs/tests/driver:ic-system-test-driver",
        "//rs/tests/nns/nns_dapp",
        "@crate_index//:anyhow",
    ],
)

system_test_nns(
    name = "small_with_query_stats",
    env = {
        "IC_ICRC1_LEDGER_WASM_PATH": "$(rootpath //rs/ledger_suite/icrc1/ledger:ledger_canister)",
        "II_WASM_PATH": "$(rootpath @ii_dev_canister//file)",
        "NNS_DAPP_WASM_PATH": "$(rootpath @nns_dapp_canister//file)",
        "SUBNET_RENTAL_WASM_PATH": "$(rootpath @subnet_rental_canister//file)",
    },
    tags = [
        "dynamic_testnet",
        "manual",
    ],
    runtime_deps = GRAFANA_RUNTIME_DEPS + IC_GATEWAY_UVM_IMAGE + [
        "//rs/ledger_suite/icrc1/ledger:ledger_canister",
        "@ii_dev_canister//file",
        "@nns_dapp_canister//file",
        "@subnet_rental_canister//file",
    ],
    deps = [
        # Keep sorted.
        "//rs/registry/subnet_type",
        "//rs/tests/consensus/utils",
        "//rs/tests/driver:ic-system-test-driver",
        "@crate_index//:anyhow",
    ],
)

system_test_nns(
    name = "sns_testing",
    env = SNS_CANISTER_ENV | {
        "II_WASM_PATH": "$(rootpath @ii_dev_canister//file)",
        "NNS_DAPP_WASM_PATH": "$(rootpath @nns_dapp_canister//file)",
        "SNS_AGGREGATOR_WASM_PATH": "$(rootpath @sns_aggregator//file)",
        "SUBNET_RENTAL_WASM_PATH": "$(rootpath @subnet_rental_canister//file)",
    },
    tags = [
        "dynamic_testnet",
        "manual",
    ],
    runtime_deps = GRAFANA_RUNTIME_DEPS + SNS_CANISTER_RUNTIME_DEPS + IC_GATEWAY_UVM_IMAGE + [
        "@ii_dev_canister//file",
        "@nns_dapp_canister//file",
        "@sns_aggregator//file",
        "@subnet_rental_canister//file",
    ],
    deps = [
        # Keep sorted.
        "//rs/registry/subnet_type",
        "//rs/tests/consensus/utils",
        "//rs/tests/driver:ic-system-test-driver",
        "//rs/tests/nns/nns_dapp",
        "@crate_index//:anyhow",
        "@crate_index//:slog",
    ],
)

system_test_nns(
    name = "medium",
    tags = [
        "dynamic_testnet",
        "manual",
    ],
    runtime_deps = GRAFANA_RUNTIME_DEPS + IC_GATEWAY_UVM_IMAGE,
    deps = [
        # Keep sorted.
        "//rs/registry/subnet_type",
        "//rs/tests/consensus/utils",
        "//rs/tests/driver:ic-system-test-driver",
        "@crate_index//:anyhow",
    ],
)

system_test_nns(
    name = "large",
    env = SNS_CANISTER_ENV | {
        "II_WASM_PATH": "$(rootpath @ii_dev_canister//file)",
        "NNS_DAPP_WASM_PATH": "$(rootpath @nns_dapp_canister//file)",
        "SNS_AGGREGATOR_WASM_PATH": "$(rootpath @sns_aggregator//file)",
        "SUBNET_RENTAL_WASM_PATH": "$(rootpath @subnet_rental_canister//file)",
    },
    tags = [
        "dynamic_testnet",
        "manual",
    ],
    runtime_deps = GRAFANA_RUNTIME_DEPS + SNS_CANISTER_RUNTIME_DEPS + IC_GATEWAY_UVM_IMAGE + [
        "@ii_dev_canister//file",
        "@nns_dapp_canister//file",
        "@sns_aggregator//file",
        "@subnet_rental_canister//file",
    ],
    deps = [
        # Keep sorted.
        "//rs/registry/subnet_type",
        "//rs/tests/consensus/utils",
        "//rs/tests/driver:ic-system-test-driver",
        "//rs/tests/nns/nns_dapp",
        "@crate_index//:anyhow",
    ],
)

system_test_nns(
    name = "io_perf_benchmark",
    tags = [
        "dynamic_testnet",
        "manual",
    ],
    runtime_deps = GRAFANA_RUNTIME_DEPS + IC_GATEWAY_UVM_IMAGE,
    deps = [
        # Keep sorted.
        "//rs/registry/subnet_type",
        "//rs/tests/consensus/utils",
        "//rs/tests/driver:ic-system-test-driver",
        "//rs/tests/nns/nns_dapp",
        "@crate_index//:anyhow",
        "@crate_index//:slog",
    ],
)

system_test_nns(
    name = "src_testing",
    env = SNS_CANISTER_ENV | {
        "XRC_WASM_PATH": "$(rootpath //rs/rust_canisters/xrc_mock:xrc_mock_canister)",
        "II_WASM_PATH": "$(rootpath @ii_dev_canister//file)",
        "NNS_DAPP_WASM_PATH": "$(rootpath @nns_dapp_canister//file)",
        "SNS_AGGREGATOR_WASM_PATH": "$(rootpath @sns_aggregator//file)",
        "SUBNET_RENTAL_WASM_PATH": "$(rootpath @subnet_rental_canister//file)",
    },
    tags = [
        "dynamic_testnet",
        "manual",
    ],
    runtime_deps = GRAFANA_RUNTIME_DEPS + SNS_CANISTER_RUNTIME_DEPS + IC_GATEWAY_UVM_IMAGE + [
        "//rs/rust_canisters/xrc_mock:xrc_mock_canister",
        "@ii_dev_canister//file",
        "@nns_dapp_canister//file",
        "@sns_aggregator//file",
        "@subnet_rental_canister//file",
    ],
    deps = [
        # Keep sorted.
        "//rs/registry/subnet_features",
        "//rs/registry/subnet_type",
        "//rs/rust_canisters/xrc_mock",
        "//rs/tests/consensus/utils",
        "//rs/tests/driver:ic-system-test-driver",
        "//rs/tests/nns/nns_dapp",
        "//rs/types/base_types",
        "@crate_index//:anyhow",
        "@crate_index//:candid",
        "@crate_index//:ic-xrc-types",
    ],
)

system_test_nns(
    name = "nns_recovery",
    tags = [
        "dynamic_testnet",
        "manual",
    ],
    uses_guestos_test_update = True,
    uses_setupos_img = True,
    runtime_deps = IC_GATEWAY_RUNTIME_DEPS,
    deps = [
        # Keep sorted.
        "//rs/limits",
        "//rs/tests/consensus/subnet_recovery:lib",
        "//rs/tests/driver:ic-system-test-driver",
        "//rs/tests/nested",
        "//rs/tests/nested/nns_recovery:common",
        "@crate_index//:anyhow",
        "@crate_index//:slog",
    ],
)
